<?php

namespace common\components\grid;

use kartik\grid\ActionColumn;
use yii\helpers\Html;

class ActionColumn2015 extends ActionColumn {
	
	public $template = '{view} {update} {delete} {rubbish} {restore}';
	
	public function init() {
		$this->width = '150px';
		parent::init();
		if (f_get('rubbish') && $this->template == '{view} {update} {delete} {rubbish} {restore}') {
			$this->template = '{delete} {restore}';
		}
	}
	
	protected function initDefaultButtons() {
		$this->buttons['restore'] = function ($url, $model, $key) {
			if (!$model->hasAttribute('is_deleted') || !f_get('rubbish')) return '';
			return Html::a('<span class="glyphicon glyphicon-share-alt"></span>', f_url(['common/restore', 'name'=>get_class($model), 'pk'=>$model->primaryKey]), [
				'title' => '还原',
				'data-confirm' => '你确定要还原吗？',
				'data-method' => 'post',
				'data-pjax' => '0',
			]);
		};
		
		$this->buttons['rubbish'] = function ($url, $model, $key) {
			if (!$model->hasAttribute('is_deleted')) return '';
			return Html::a('<span class="glyphicon glyphicon-trash"></span>', f_url(['common/rubbish', 'name'=>get_class($model), 'pk'=>$model->primaryKey]), [
				'title' => '加入回收站',
				'data-confirm' => '你确定要加入回收站吗？',
				'data-method' => 'post',
				'data-pjax' => '0',
			]);
		};
		
		$this->buttons['delete'] = function ($url, $model, $key) {
			if ($model->hasAttribute('is_deleted') && !f_get('rubbish')) return '';
			return Html::a('<span class="glyphicon glyphicon-remove"></span>', f_url(['common/delete', 'name'=>get_class($model), 'pk'=>$model->primaryKey]), [
				'title' => '彻底删除',
				'data-confirm' => '你确定要删除这条记录吗？',
				'data-method' => 'post',
				'data-pjax' => '0',
			]);
		};
		parent::initDefaultButtons();
	}
}

?>